from django.db import models
from django.utils.translation import ugettext_lazy as _
from garetjax.db.models import GroupedOrderedModel

class Menu(GroupedOrderedModel):
    group_by = 'parent'
    
    name = models.SlugField(max_length=100, unique=True)
    title = models.CharField(_('title'), max_length=100)
    parent = models.ForeignKey('self', null=True, blank=True, related_name='items', limit_choices_to = {'href__exact': ''})
    href = models.CharField(_('link'), blank=True, max_length=100)
    
    def path(self):
        if self.parent is None:
            return '/%s/' % self.name
        
        import os
        return os.path.join(self.parent.path(), self.name, '')
    
    def __unicode__(self):
        return self.name
    